ARG LISTEN_PORT=8012

ARG ACTIVE_PROFILE=prod

FROM maven:3.6-alpine as mvnbuilder

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories


WORKDIR /opt/

RUN  mkdir ~/.ssh && echo $'Host *\n\
  StrictHostKeyChecking no\n\
  UserKnownHostsFile=/dev/null\n'\
  > ~/.ssh/config \
 && apk add --no-cache git  openssh-client  && ssh-keygen -q -N " " -f ~/.ssh/id_rsa


COPY ./git-key/id_rsa.pub   /tmp/
COPY ./git-key/id_rsa /tmp/


RUN  chmod 700 /tmp/id_rsa.pub && chmod 700 /tmp/id_rsa

RUN cat /tmp/id_rsa.pub > ~/.ssh/id_rsa.pub && cat /tmp/id_rsa > ~/.ssh/id_rsa && sed -i 's/#   StrictHostKeyChecking ask/StrictHostKeyChecking no/' /etc/ssh/ssh_config

RUN git init && git remote add origin git@gitee.com:wen2020/micro-service.git


RUN git clone --depth 1 --progress git@gitee.com:wen2020/micro-service.git

ADD ./settings.xml /opt/micro-service/

ADD ./settings.xml /opt/micro-service/multi-eureka-server/

WORKDIR /opt/micro-service/


WORKDIR /opt/micro-service/multi-eureka-server/


RUN mvn clean package -T 1C -Dmaven.test.skip=true -Dmaven.compile.fork=true  --settings settings.xml

FROM ibm-semeru-runtimes:open-8-jdk

COPY --from=mvnbuilder /opt/micro-service/multi-eureka-server/target/*.jar /opt/


WORKDIR /opt/


RUN mv multi-eureka-server.jar app.jar
ARG LISTEN_PORT

ARG ACTIVE_PROFILE

EXPOSE $LISTEN_PORT

ENV LISTEN_PORT=$LISTEN_PORT

ENV ACTIVE_PROFILE=$ACTIVE_PROFILE

ENV JAVA_OPTS=" -server -Djava.security.egd=file:/dev/./urandom -XX:+UseContainerSupport  -XX:MaxRAMPercentage=80.0 -Xms512m -Xmx512m -Duser.timezone=GMT+8 "

ENTRYPOINT ["sh","-c","java ${JAVA_OPTS} -jar  -Dspring.profiles.active=${ACTIVE_PROFILE} -Dserver.port=${LISTEN_PORT}  /opt/app.jar ${BOOTSTRAP_OPTS}"]
